package net.zjitc.filter;

import net.zjitc.pojp.AdminUser;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Created by Administrator on 2017/11/15.
 */
@WebFilter(filterName = "AdminFilter")
public class AdminFilter implements Filter {
    public void destroy() {
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        HttpServletRequest req= (HttpServletRequest) request;
        HttpSession session=req.getSession();
        AdminUser admin= (AdminUser) session.getAttribute("adminUser");
        if(admin==null){
            req.getRequestDispatcher("/admin/login.jsp").forward(request,response);
        }else{
            chain.doFilter(request,response);
        }

    }

    public void init(FilterConfig config) throws ServletException {

    }

}
